package com.sxbbc.common.basics.push;

import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.Notification;

import java.util.List;

/**
 * 推送 工具
 *
 * @author leehao
 * @date 2019-06-17
 */
public class PushUtil {

    private static PushUtil pushUtil = null;

    public static PushUtil getInstance(){
        if (pushUtil == null) {
            synchronized (PushUtil.class){
                if (pushUtil == null) {
                    pushUtil = new PushUtil();
                }
            }
        }
        return pushUtil;
    }

    /**
     * 指定推送单个用户
     * @param Token 手机设备的串号
     * @param Contents 消息内容,这个内容会在android通知显示，
     */
    public PushPayload buildPushObject(String Token,String Contents) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.android_ios())
                .setAudience(Audience.alias(Token))
                .setNotification(Notification.newBuilder().setAlert(Contents).build())
                .build();
    }

    /**
     * 指定推送多个用户
     * @param Token 手机设备的串号
     * @param Contents 消息内容,这个内容会在android通知显示，
     */
    public PushPayload buildPushObject(List<String> Token, String Contents) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.android_ios())
                .setAudience(Audience.alias(Token))
                .setNotification(Notification.newBuilder().setAlert(Contents).build())
                .build();
    }

    /**
     * 推送全部
     * @param Contents 消息内容,这个内容会在android通知显示，
     */
    public PushPayload buildAllPushObject(String Contents) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.android_ios())
                .setAudience(Audience.all())
                .setNotification(Notification.newBuilder().setAlert(Contents).build())
                .build();
    }
}
